﻿<?php 
	require_once('common.php');
	/*Accept: */
	/*	Accept-Language: zh-cn,en-us;q=0.5
		Content-Type: application/x-www-form-urlencoded
		User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
		Host: 要发送到的主机地址
		Content-Length: 发送数据的长度
		Pragma: no-cache
		Cache-Control: no-cache
		username=php&password=iask   //post发送的数据
	 *
	 */
	
	
	/*fsocket模拟get提交*/
	echo "<h2>fsocket模拟get提交</h2>";
	$url=getHost()."spiders/test.php?info=你好";
	$info = parse_url($url);  
	$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);  
	$head = "GET ".$info['path']."?".$info["query"]." HTTP/1.0\r\n";  
	$head .= "Host: ".$info['host']."\r\n";  
	$head .= "\r\n";  
	$write = fputs($fp, $head);  
	while (!feof($fp)){  
		$line = fgets($fp); 
		echo $line."<br>";  
		}
	
	/*fsocket模拟post提交*/
	echo "<h2>fsocket模拟post提交</h2>";
	$query="info=你好";
	$info = parse_url($url);  
	$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);  
	$head = "POST ".$info['path']." HTTP/1.0\r\n";  
	$head .= "Host: ".$info['host']."\r\n";  
	$head .= "Referer: http://".$info['host'].$info['path']."\r\n";  
	$head .= "Content-type: application/x-www-form-urlencoded\r\n";  
	$head .= "Content-Length: ".strlen(trim($query))."\r\n";  
	$head .= "\r\n";  
	$head .= trim($query);  
	$write = fputs($fp, $head);  
	while (!feof($fp))  {  
		$line = fgets($fp);  
		echo $line."<br>";  
		}
?>
